
<template>
  <div class="app-container">
    <el-form
      ref="listFilterRef"
      :model="list.filter"
      inline
      class="list-filter"
    >  
        <el-form-item prop="name">
          <el-input v-model="list.filter.name" placeholder="输入商品名称搜索" clearable>
            <i slot="prefix" class="el-input__icon el-icon-search"/>
          </el-input>
        </el-form-item>

      <el-form-item prop="status">
        <KiSelect
          :index.sync="list.filter.status"
          :options="['停用', '启用']"
          placeholder="状态"
        />
      </el-form-item>

        <el-form-item prop="regEndTime">
          <TimeRangePicker
            value-format="yyyy-MM-dd"
            :start.sync="list.filter.startDate"
            :end.sync="list.filter.endDate"
            placeholder="商品创建开始时间/商品创建结束时间"
          />
        </el-form-item>
      
      <el-button @click="reset">重置</el-button>
    </el-form>

    <div class="table-operation">
      <div>
        <AuthButton @click="c" name="新增" />
        <ExportExcel
          url="/sot-admin-api/vip/vip-product/export"
          :param="list.filter"
          :disabled="!(list.data && list.data.length > 0)"
        />
      </div>
      <el-pagination
        v-bind="elPaginationProps"
        :total="list.total"
        :currentPage.sync="list.filter.pageNo"
        :pageSize.sync="list.filter.pageSize"
      />
    </div>

    <el-table
      stripe
      v-loading="list.loading"
      :data="list.data"
      border
      fit
    >
      <el-table-column align="center" type="index"/>
      <el-table-column label="商品编码" prop="id"/>
      <el-table-column label="商品名称" prop="name"/>
      <el-table-column label="兑换积分" prop="integral"/>
      <el-table-column label="状态" align="center">
        <template slot-scope="{ row: { id, status } }">
          <KiPopSwitch
            v-bind="popSwitchProps(status)"
            @change="updateStatus({ id, status: status ^ 1 })"
          />
        </template>
      </el-table-column>
      <el-table-column label="创建时间" prop="createTime"/>
      <el-table-column label="最后修改时间" prop="updateTime"/>
      <el-table-column align="center" label="操作">
        <template slot-scope="{row}">
          <AuthButton @click="r(row)" name="查看" />
          <AuthButton @click="u(row)" name="编辑" />
          <AuthButton @click="d(row)" name="删除" />
        </template>
      </el-table-column>
    </el-table>

    <KiFormDialog
      :show.sync="form.show"
      :title="formTitle"
      v-model="form.data"
      :submit="submitForm"
      :readonly="form.status === 'r'"
      ref="formRef"
    >
      <template #el-form>
        <h3 class="subtitle"><span>基本信息</span></h3>
          <el-form-item label="商品名称" prop="name"  :verify="{ minLength: 2, maxLength: 20 , required: true}">
            <el-input v-model="form.data.name" clearable maxlength="20" show-word-limit placeholder="请输入商品名称"/>
          </el-form-item>
          <el-form-item label="兑换积分" prop="integral" verify>
            <el-input-number v-model="form.data.integral" :min="1" :max="999999" :precision="0" placeholder="输入大于0的数"/>
          </el-form-item>
          <el-form-item label="商品库存" prop="productTotal" verify>
            <el-input-number v-model="form.data.productTotal" :min="1" :max="99999" :precision="0" placeholder="输入大于0的数"/>
          </el-form-item>

        <h3 class="subtitle"><span>商品详情</span></h3>
          <el-form-item label="图文介绍" prop="pictureTextInfo" verify>
            <MiniMCE
              v-model="form.data.pictureTextInfo"
              :disabled="form.status==='r'||form.submitting"
            />
          </el-form-item>
          <el-form-item label="封面图" prop="coverUrl" verify>
            <Imgpond
              v-model="form.data.coverUrl"
              value-type="string"
              :count="1"
              aspectRatio="375/261"
            />
          </el-form-item>
          <el-form-item label="详情图片" prop="pictureUrl" verify>
            <Imgpond
              v-model="form.data.pictureUrl"
              value-type="array"
              :count="10"
              aspectRatio="375/261"
            />
          </el-form-item>
      </template>
    </KiFormDialog>
  </div>
</template>

<script>
import pageMixin from '@/utils/pageMixin'

export default {
  mixins: [pageMixin],
  data() {
    return {
    }
  },
  setup: () =>
    useAdmateAdapter({
      urlPrefix: 'sot-admin-api/vip/vip-product',
    }
  )
}
</script>